import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  plugins:[createPersistedState()],
    state: {
      //这里放全局参数
      token:'',
      role:'',
      user:{},
      remember:false,
    },
  
    mutations: {
  
      //这里是set方法
      SET_TOKEN(state,token) {
          state.token = token;
      },
      SET_ROLE(state,role) {
        state.role = role;
      },
      SET_USER(state,user) {
          state.user = user;
      },
      SET_PASSWORD(state,password) {
          state.user.password = password;
      },
      SET_MESSAGES(state,messages) {
        state.user.messages = messages;
      },
      SET_REMEMBER(state,bool) {
        state.remember = bool;
      }
    },
  
      getters: {
  
      //get方法
      getToken: state => state.token,
      getRole: state => state.role,
      getUser: state => state.user,
      getRemember: state => state.remember,
      getMessages: state => state.user.messages
      },
  
    actions: {
  
      //这个部分我暂时用不上
  
    },
  
    modules: {
  
  //这里是我自己理解的是为了给全局变量分组，所以需要写提前声明其他store文件，然后引入这里
  
    }
  
  })